package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.H_SocketClient;
import com.chinanet.utils.pon.OperationType;

import java.util.HashMap;
import java.util.Map;
/**
 * @author zsf
 * @date 2018/1/29 14:58
 * @desc 华为PON网管-新建宽带41
 */
public class HW_Query_PON_New_Broadband_41 implements WorkInterFace {
    @Override
    public String getName() {
        return "华为PON网管-新建宽带41";
    }

    @Override
    public String getDesciption() {
        return "";
    }

    @Override
    public int getVersion() {
        return 0;
    }

    @Override
    public Attr[] getInAttrs() {
        Attr[] in = new Attr[5];
        in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
        in[1] = new Attr("PONID", "PON的ID，如：查询OLT设备上0框4槽1端口的光模块信息，PONID为NA-0-4-1", AttrType.TYPE_String, true);
        in[2] = new Attr("ONUID", "ONU标识，可以按ONU_NAME/MAC/LOID/ONU_NUMBER取值，用于唯一标识PON口的ONU", AttrType.TYPE_String, true);
        in[3] = new Attr("SVLAN", "", AttrType.TYPE_String, true);
        in[4] = new Attr("CVLAN", "", AttrType.TYPE_String, true);
        return in;
    }

    @Override
    public Attr[] getOutAttrs() {
        Attr[] out = new Attr[3];
        out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
        out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
        out[2] = new Attr("show", "日志输出", AttrType.TYPE_String, true);
        return out;
    }

    @Override
    public Map<String, Object> init(Map<String, Object> data) {
        Map<String, Object> outmap = new HashMap<>();
        String ip ="134.103.69.185";
        int port = 13027;
        H_SocketClient hclient = new H_SocketClient(ip, port);
        HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
        attrsin.setUsername("nxzcxc");
        attrsin.setPassword("asdf1234");
        attrsin.setOLTID((String)data.get("OLTID"));
        attrsin.setPONID((String)data.get("PONID"));
        attrsin.setONUIDTYPE("LOID");
        attrsin.setONUID((String)data.get("ONUID"));
        attrsin.setSVLAN((String)data.get("SVLAN"));
        attrsin.setCVLAN((String)data.get("CVLAN"));
        Map<String, Object> inmap = hclient.init(attrsin,
                OperationType.TYPE_HW_Query_PON_Broadband_41);

        boolean flag = (Boolean) inmap.get("flag");
        if(flag) {
            outmap.put("flag", 1);
            outmap.put("show","执行成功");
        } else {
            outmap.put("flag", 0);
            outmap.put("show","执行失败，log : "+inmap.get("log"));
        }
        outmap.put("log", inmap.get("log"));


        return outmap;
    }
}
